import request from "@/utils/request.ts";
import {
  Attr,
  AttrResponseData,
  CategoryResponseData,
} from "@/api/product/attr/type.ts";

enum API {
  //     GET /admin/product/getCategory1   获取一级分类
  C1_URL = "/admin/product/getCategory1",
  //     GET /admin/product/getCategory2/{category1Id}   获取二级分类
  C2_URL = "/admin/product/getCategory2/",
  //     GET /admin/product/getCategory3/{category2Id}   获取三级分类
  C3_URL = "/admin/product/getCategory3/",
  // GET /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}  获取属性列表
  ATTR_URL = "/admin/product/attrInfoList/",
  // post /admin/product/saveAttrInfo 保存属性
  SAVE_ATTR_URL = "/admin/product/saveAttrInfo",
  //   DELETE /admin/product/deleteAttr/{attrId} 删除属性
  DELETE_ATTR_URL = "/admin/product/deleteAttr/",
}

// 获取一级分类
export const reqC1 = () => request.get<any, CategoryResponseData>(API.C1_URL);
// 获取二级分类
export const reqC2 = (category1Id: number | string) =>
  request.get<any, CategoryResponseData>(API.C2_URL + category1Id);
// 获取三级分类
export const reqC3 = (category2Id: number | string) =>
  request.get<any, CategoryResponseData>(API.C3_URL + category2Id);

// 获取属性列表
export const reqAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, AttrResponseData>(
    API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`,
  );

// 保存属性
// data: 待保存的属性数据 有id则为修改，无id则为添加
export const reqSaveAttr = (data: Attr) =>
  request.post<any, any>(API.SAVE_ATTR_URL, data);

// 删除属性
export const reqDeleteAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETE_ATTR_URL + `${attrId}`);
